// proxy 第二个参数handler

function reactive(target) {
  const handler = {
    get(target, key, receiver) {
      console.log('get');
      // 添加get参数接收器-receiver, 并传递到反射调用中， 保证对象具有继承或函数使用时的正确
      return Reflect.get(target, key, receiver);
    },
    set(target, key, value, receiver) {
      console.log('set');
      return Reflect.set(target, key, value, receiver);
    }
  };
  return new Proxy(target, handler);
}

let product = reactive({ price: 5, quantity: 2 });

console.log(product.price);

product.price = 8;

console.log(product.price);

// get
// 5
// set
// get
// 8
